import request from '@/utils/axios';

const api_name = '/admin/product/category'
// 根据parentId获取下级节点
export const FindCategoryByParentIdApi = (parentId: number) => {
  return request({
    url: `${api_name}/findByParentId/${parentId}`,
    method: 'get',
  })
}

// 获取所有分类节点
export const findAllNodesApi = () => {
  return request({
    url: `${api_name}/findAllNodes`,
    method: 'get',
  })
}

// 导出
export const exportCategoryDataApi = () => {
  return request({
    url: `${api_name}/exportData`,
    method: 'get',
    responseType: 'blob'
  })
}

// 导入
export const importCategoryDataApi = (file: File) => {
  return request({
    url: `${api_name}/importData`,
    method: 'post',
    data: file,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

// 添加分类
export const addCategoryApi = (data: any) => {
  return request({
    url: `${api_name}/save`,
    method: 'post',
    data
  })
}

// 修改分类
export const updateCategoryApi = (data: any) => {
  return request({
    url: `${api_name}/update`,
    method: 'put',
    data
  })
}

// 删除分类
export const removeCategoryApi = (id: number) => {
  return request({
    url: `${api_name}/delById/${id}`,
    method: 'delete'
  })
}